package argo.hot100.greedy;

public class Jump {

    public int jump(int[] nums) {

        int step = 0;
        int preMaxPosition = 0;
        int curMaxPosition = 0;

        for (int i = 0; i < nums.length - 1; i++) {
            curMaxPosition = Math.max(i + nums[i], curMaxPosition);
            if (i == preMaxPosition) {
                preMaxPosition = curMaxPosition;
                step++;
            }
        }
        return step;

    }


    public int jump1(int[] nums) {

        int step = 0;
        int position = nums.length - 1;
        while (position > 0) {
            for (int i = 0; i < nums.length; i++) {
                if (nums[i] + i >= position) {
                    position = i;
                    step++;
                    break;
                }
            }
        }

        return step;

    }
}
